<template>
	<div class="teacher-information-export">
		<Form ref="formValidate" :model="formValidate" :label-width="80" :rules="ruleValidate">
			<div style="border-bottom: 1px solid #e9e9e9;padding-bottom:6px;margin-bottom:6px;">
				<Checkbox :indeterminate="indeterminate" :value="checkAll" @click.prevent.native="handleCheckAll">全选</Checkbox>
			</div>
			<FormItem label="选择要导出的内容" style="width:100%;">
				<CheckboxGroup v-model="formValidate.condition">
					<Checkbox label="teacher_name" disabled>
						姓名
					</Checkbox>
					<Checkbox label="nation">
						民族
					</Checkbox>
					<Checkbox label="imgphotos">
						公安身份证备案照片
					</Checkbox>
					<Checkbox label="idcard">
						身份证号
					</Checkbox>
					<Checkbox label="gender">
						性别
					</Checkbox>
					<Checkbox label="birthday">
						出生日期
					</Checkbox>
					<Checkbox label="type">
						人才类型
					</Checkbox>
					<Checkbox label="unitname">
						单位名称
					</Checkbox>
					<Checkbox label="email">
						电子邮箱
					</Checkbox>
					<Checkbox label="telnumber">
						联系电话
					</Checkbox>
					<Checkbox label="nationality">
						国籍
					</Checkbox>
					<Checkbox label="workstatus">
						在岗状态
					</Checkbox>
					<Checkbox label="workdate">
						参加工作时间
					</Checkbox>
					<Checkbox label="jobtitle">
						最高职称
					</Checkbox>
					<Checkbox label="education">
						最高学历
					</Checkbox>
					<Checkbox label="degree">
						最高学位
					</Checkbox>
					<Checkbox label="nativeprovince">
						籍贯-省份
					</Checkbox>
					<Checkbox label="nativecity">
						籍贯-市
					</Checkbox>
					<Checkbox label="nativecounty">
						籍贯-县城
					</Checkbox>
					<Checkbox label="birthprovince">
						出生地-省份
					</Checkbox>
					<Checkbox label="birthcity">
						出生地-市
					</Checkbox>
					<Checkbox label="birthcounty">
						出生地-县城
					</Checkbox>
	
					<Checkbox label="mastersupervisor">
						是否硕导
					</Checkbox>
					<Checkbox label="teach">
						是否博导
					</Checkbox>
					<Checkbox label="talentcategory_six">
						人才类别(按六支队伍分)
					</Checkbox>
					<Checkbox label="talentcategory_nine">
						人才类别(按九支队伍分)
					</Checkbox>
					<Checkbox label="cmbProvince3">
						现住址-省
					</Checkbox>
					<Checkbox label="cmbcity3">
						现住址-市
					</Checkbox>
					<Checkbox label="cmbcounty3">
						现住址-县
					</Checkbox>
					<Checkbox label="cmbProvince2">
						户籍所在地-省
					</Checkbox>
					<Checkbox label="cmbcity2">
						户籍所在地-市
					</Checkbox>
					<Checkbox label="cmbcounty2">
						户籍所在地-县
					</Checkbox>
					<Checkbox label="signimg">
						本人签字图片
					</Checkbox>
				</CheckboxGroup>
			</FormItem>
	
			<FormItem>
				<a href="" class="teacher-information-export">已确保您的浏览器已信任本网页</a>
			</FormItem>
			<FormItem>
				<Button type="primary" @click="handleSubmit('formValidate')">提交</Button>
	
				<Button type="ghost" style="margin-left: 8px" @click="handleReset('formValidate')">重置</Button>
			</FormItem>
			<div style="clear:both"></div>
		</Form>
	
	</div>
</template>

<script>
	export default {
		data() {
			return {
				look: false,
				indeterminate: true,
				checkAll: false,
				user_id: null,
				condition: [],
				formValidate: {
					condition: [
						'teacher_name'
					]
				},
				formItem: [],
	
				ruleValidate: {
					condition: [{
						type: "array",
						min: 1,
						required: true,
						message: "请选择导出数据",
						trigger: "change"
					}]
				}
			};
		},
	
		methods: {
			handleCheckAll() {
				if (this.indeterminate) {
					this.checkAll = false;
				} else {
					this.checkAll = !this.checkAll;
				}
				this.indeterminate = false;
	
				if (this.checkAll) {
					this.formValidate.condition = [
						"teacher_name",
						"nation",
						"imgphotos",
						"idcard",
						"gender",
						"birthday",
						"nativeprovince",
						"nativecity",
						"nativecounty",
						"birthprovince",
						"birthcity",
						"birthcounty",
						"type",
						"unitname",
						"email",
						"telnumber",
						"nationality",
						"politicaltype",
						"workstatus",
						"workdate",
						"jobtitle",
						"education",
						"degree",
						"mastersupervisor",
						"teach",
						"talentcategory_six",
						"talentcategory_nine",
						"cmbProvince3",
						"cmbcity3",
						"cmbcounty3",
						"cmbProvince2",
						"cmbcity2",
						"cmbcounty2",
						"signimg"
					];
				} else {
					this.formValidate.condition = ["teacher_name"];
				}
			},
			handleSubmit(name) {
				let cond = [];
				// for(let item in this.condition){
				//      cond.push(this.condition[item])
				//   }
	
				this.formValidate.condition.forEach((val, index) => {
					cond += val + ",";
				});
				cond = cond.substring(0, cond.lastIndexOf(","));
	
				this.$http
					.get("api/teacher/v1/teacher/exportExcel/" + cond)
					.then(val => {
							window.open(val.data.url)
							this.$Message.error('导出成功!');	
							this.$emit("requery", true);	
					}).catch(err => this.$Message.error("导出失败！"));
			},
	
			handleReset(name) {
				this.$refs[name].resetFields();
			}
		}
	};
</script>

<style lang="less">
	.teacher-information-export {
		color: red
	}

	
</style>

